//
//  FCWalletSendVC.m
//  FundChain
//
//  Created by 肖浩然的mac on 2018/3/2.
//  Copyright © 2018年 RUIXIN. All rights reserved.
//

#import "FCWalletSendVC.h"
#import "FCPopupView.h"
#import "FCImportPinVC.h"
#import "FCSendScanCodeVC.h"
#import <IQKeyboardManager/IQKeyboardManager.h>
@interface FCWalletSendVC ()<UITextFieldDelegate>{
    UIView     *_dimView;
}
/* 地址 */
@property (strong, nonatomic) UITextField *addressField;
/* 多少btc */
@property (strong, nonatomic) UITextField *sendField;

/* 货币余额 */
@property (strong, nonatomic)  UILabel *balanceLabel;
/* 更变的币种 */
@property (strong, nonatomic) UILabel *usdLable;
/* 多少usd */
@property (strong, nonatomic) UILabel *moneyCountLable;
/* 等值多少 */
@property (strong, nonatomic) UILabel *eqBtcLable;
/* 接收 */
@property (strong, nonatomic) UITextField *receiveField;
/* 币种 */
@property (strong, nonatomic)  UILabel *currencyLable;
/* 汇率 */
@property (copy, nonatomic) NSString *priceStr;
/* feeCountLable */
@property (strong, nonatomic) UILabel *feeCountLable;
/* sendBtn */
@property (strong, nonatomic)UIButton *sendBtn;
/* <#Annotation#> */
@property (strong, nonatomic) UILabel *equalLabel;
/* <#Annotation#> */
@property (strong, nonatomic) UIView *viewLine3;
/* <#Annotation#> */
@property (strong, nonatomic) UILabel *sendLable;
/*==============popView=============*/
/* amt */
@property (strong, nonatomic) UILabel *popMoneyCountLable;
/* balance */
@property (strong, nonatomic) UILabel *popEqBtcLable;
/* fee */
@property (strong, nonatomic) UILabel *popFeeCountLable;
/* 地址 */
@property (strong, nonatomic) UILabel *popAddressLabel;
/* 币种 */
@property (strong, nonatomic) UILabel *popUsdLable ;
/* pin */
@property (copy, nonatomic) NSString *pinStr;

/* <#Annotation#> */
@property (strong, nonatomic) UILabel *currencyUSDLable;

/* <#Annotation#> */
@property (strong, nonatomic) UILabel *feeUsdLabel;

/* FCBalanceModel */
@property (strong, nonatomic) FCBalanceModel *balanceModel;

/* 是否获取pin成功 */
@property (assign, nonatomic) BOOL isSuccess;
@end

@implementation FCWalletSendVC

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [IQKeyboardManager sharedManager].enable = NO;
    [self loadData];
}
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [IQKeyboardManager sharedManager].enable = YES;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [FCLocalUserHelper saveIsMainVC:@"0"];
    //监听键盘
    if ([self.walletId isEqualToString:@"1009"]) {
        
        
        
        
    }else{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    }
    self.view.backgroundColor = kWhiteColor;
    
    [self setupUI];
   
    
}
-(void)loadData{
    
                FCBalanceModel *balanceModel = [FCLocalUserHelper getFMDBBalanceData:self.walletId];
                    self.balanceModel = balanceModel;
                switch ([balanceModel.walletId integerValue]) {
                    case 1001:
                    {
                        
                        self.eqBtcLable.text = [NSString stringWithFormat:@"(≈%@ %@)",balanceModel.balance,Localized(@"BTC")];
                        self.currencyLable.text = Localized(@"BTC");
                        
                        
                    }
                        break;
                    case 1005:
                    {
                        
                        self.eqBtcLable.text = [NSString stringWithFormat:@"(≈%@ %@)",balanceModel.balance,Localized(@"LTC")];
                        self.currencyLable.text = Localized(@"LTC");
                        
                        
                    }
                        break;
                    case 1006:
                    {
                        
                        self.eqBtcLable.text = [NSString stringWithFormat:@"(≈%@ %@)",balanceModel.balance,Localized(@"BCH")];
                        self.currencyLable.text = Localized(@"BCH");
                        
                    }
                        break;
                    case 1009:
                    {
                        
                        self.balanceLabel.text = Localized(@"CCH钱包余额");
                        self.eqBtcLable.text = [NSString stringWithFormat:@"(≈%@ %@)",balanceModel.balance,Localized(@"CCH")];
                        self.currencyLable.text = Localized(@"CCH");
                       
                        
                        
                    }
                        break;
                    case 1010:
                    {
                        
                        self.eqBtcLable.text = [NSString stringWithFormat:@"(≈%@ %@)",balanceModel.balance,Localized(@"ZEC")];
                        self.currencyLable.text = Localized(@"ZEC");
                        
                    }
                        break;
                        
                    default:
                        break;
                }
                
                NSArray *arr = balanceModel.currentResult;
                [arr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                    FCCurrentResultModel *model = [FCCurrentResultModel mj_objectWithKeyValues:obj];
                    if ([model.currentId isEqualToString:@"8001"]) {
                        
                        self.moneyCountLable.text = model.amt;
                        self.priceStr = model.price;
                        float result = [balanceModel.fee floatValue]*[model.price floatValue];
                        if ([balanceModel.walletId isEqualToString:@"1009"]) {
                            
                        }else{
                            self.feeCountLable.text = [NSString stringWithFormat:@"%.2f",result];
                        }
                        
                       
                    }
//                    if ([self.walletId isEqualToString:@"1009"]) {
//
//                        self.feeUsdLabel.text = @"CCH";
//                        self.feeCountLable.text = [NSString stringWithFormat:@"%.2f",[balanceModel.fee floatValue]];
//                    }
                    FCCurrentResultModel *currentResultModel = self.currentResultModel;
                    
                    if ([currentResultModel.walletId isEqualToString:self.walletId]) {
                        self.usdLable.text = currentResultModel.currentName;
                        float result = [currentResultModel.price floatValue]*[balanceModel.balance floatValue];
                        self.moneyCountLable.text = [NSString stringWithFormat:@"%.2f",result] ;
                        self.currencyUSDLable.text = currentResultModel.currentName;
                        float resultFee = [balanceModel.fee floatValue]*[currentResultModel.price floatValue];
                        if ([model.walletId isEqualToString:@"1009"]) {
                            
                        }else{
                            self.feeCountLable.text = [NSString stringWithFormat:@"%.2f",resultFee];
                            self.feeUsdLabel.text = currentResultModel.currentName;
                        }
                        
                        
                    }
                   
                }];
    

    
}
#pragma mark-seng事件
-(void)sendBtnClick{
    
    if (self.sendField.text.trimWhitespace.length <= 0 || self.addressField.text.trimWhitespace.length <= 0 ) {
        return;
    }
    if ([self.sendField.text floatValue] <= 0) {
        [self showAlert:Localized(@"交易金额不能为0")];
        return;
    }
    if ([self.sendField.text floatValue] > [self.balanceModel.balance floatValue]) {
        [self showAlert:Localized(@"余额不足")];
        return;
    }
    //UIview
    _dimView = [[UIView alloc]initWithFrame:CGRectMake(0, 570*KScreenHeightScale1334, SCREEN_WIDTH, 765*KScreenHeightScale1334)];
    
    _dimView.backgroundColor = kWhiteColor;
    _dimView.layer.cornerRadius = 2.5;
    _dimView.layer.masksToBounds = YES;
    UIView *fristView = [UIView new];
    [_dimView addSubview:fristView];
    [fristView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.top.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.height.mas_equalTo(100*KScreenHeightScale1334);
    }];
    //请输入密码
    UILabel *titleLabel = [UILabel new];
    [fristView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.left.mas_equalTo(30*KScreenWidthScale750);
        
    }];
    titleLabel.text = Localized(@"确认订单信息");
    titleLabel.font = Kfont(36);
    //退出按钮
    UIButton *backBtn = [UIButton new];
    [fristView addSubview:backBtn];
    [backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.right.mas_equalTo(-30*KScreenWidthScale750);
    }];
    [backBtn setImage:[UIImage imageNamed:@"cancel"] forState:UIControlStateNormal];
    //分割线
    UIView *viewLine =[UIView new];
    [_dimView addSubview:viewLine];
    [viewLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(fristView.mas_bottom);
        make.height.mas_equalTo(1);
    }];
    viewLine.backgroundColor =kLineColor;
    
    //Amount
    UILabel *amountLabel = [UILabel new];
    [_dimView addSubview:amountLabel];
    [amountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(30*KScreenWidthScale750);
        make.top.mas_equalTo(viewLine.mas_bottom).offset(40*KScreenHeightScale1334);
        
    }];
    amountLabel.font = Kfont(32);
    amountLabel.text = Localized(@"数量");
    amountLabel.textColor = kGrayColor;
    //交易金额
    UILabel *popMoneyCountLable = [UILabel new];
    self.popMoneyCountLable = popMoneyCountLable;
    [_dimView addSubview:popMoneyCountLable];
    [popMoneyCountLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(amountLabel.mas_bottom).offset(20*KScreenHeightScale1334);
        make.left.mas_equalTo(30*KScreenWidthScale750);
    }];
    popMoneyCountLable.text = self.sendField.text;
    popMoneyCountLable.font = Kfont(40);
    //usd
    UILabel *popUsdLable = [UILabel new];
    self.popUsdLable = popUsdLable;
    [_dimView addSubview:popUsdLable];
    [popUsdLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(popMoneyCountLable).offset(-2);
        make.left.mas_equalTo(popMoneyCountLable.mas_right).offset(10*KScreenWidthScale750);
    }];
    popUsdLable.text = self.currencyLable.text;
    popUsdLable.font = Kfont(32);
    popUsdLable.textColor = kOrderColor;
    //等值多少比特币
    UILabel *popEqBtcLable = [UILabel new];
    self.popEqBtcLable = popEqBtcLable;
    [_dimView addSubview:popEqBtcLable];
    [popEqBtcLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(popMoneyCountLable).offset(-4);
        make.left.mas_equalTo(popUsdLable.mas_right).offset(20*KScreenWidthScale750);
    }];
    
    FCCurrentResultModel *currentResultModel = self.currentResultModel;
    
    if ([currentResultModel.walletId isEqualToString:self.walletId]) {
        
        popEqBtcLable.text = [NSString stringWithFormat:@"(≈%@ %@)",self.receiveField.text,currentResultModel.currentName];
        
    }else{
       popEqBtcLable.text = [NSString stringWithFormat:@"(≈%@ USD)",self.receiveField.text];
    }
    if ([self.walletId isEqualToString:@"1009"]) {
        popEqBtcLable.hidden = YES;
    }
    popEqBtcLable.font = Kfont(28);
    popEqBtcLable.textColor = kGrayColor;
    //Fee
    UILabel *popFeeLable = [UILabel new];
    [_dimView addSubview:popFeeLable];
    [popFeeLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(popMoneyCountLable.mas_bottom).offset(60*KScreenHeightScale1334);
        make.left.mas_equalTo(popMoneyCountLable);
    }];
    popFeeLable.text = Localized(@"手续费");
    popFeeLable.font = Kfont(32);
    popFeeLable.textColor = kGrayColor;
    //fennCountLabel
    UILabel *popFeeCountLable = [UILabel new];
    self.popFeeCountLable = popFeeCountLable;
    [_dimView addSubview:popFeeCountLable];
    [popFeeCountLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(popFeeLable.mas_bottom).offset(20*KScreenHeightScale1334);
        make.left.mas_equalTo(30*KScreenWidthScale750);
    }];
    popFeeCountLable.text = self.feeCountLable.text;
    popFeeCountLable.font = Kfont(36);
    popFeeCountLable.textColor = kDarkBlackColor;
    //usdLabel
    UILabel *popFeeUsdLabel = [UILabel new];
    [_dimView addSubview:popFeeUsdLabel];
    [popFeeUsdLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(popFeeCountLable.mas_bottom).offset(-2);
        make.left.mas_equalTo(popFeeCountLable.mas_right).offset(10*KScreenWidthScale750);
    }];
    popFeeUsdLabel.text = @"USD";
    popFeeUsdLabel.font = Kfont(28);
    popFeeUsdLabel.textColor = kOrderColor;
    popFeeUsdLabel.text = self.feeUsdLabel.text;
    //sendto
    UILabel *popSendLabel = [UILabel new];
    [_dimView addSubview:popSendLabel];
    [popSendLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(popFeeUsdLabel.mas_bottom).offset(60*KScreenHeightScale1334);
        make.left.mas_equalTo(amountLabel);
    }];
    popSendLabel.text = Localized(@"发给");
    popSendLabel.font = Kfont(32);
    popSendLabel.textColor = kGrayColor;
    //address
    UILabel *popAddressLabel = [UILabel new];
    self.popAddressLabel = popAddressLabel;
    [_dimView addSubview:popAddressLabel];
    [popAddressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(popSendLabel.mas_bottom).offset(30*KScreenHeightScale1334);
        make.left.mas_equalTo(amountLabel);
        make.right.mas_equalTo(-30*KScreenWidthScale750);
    }];
    popAddressLabel.text = self.addressField.text;
    popAddressLabel.font = Kfont(28);
    popAddressLabel.textColor = kDarkBlackColor;
    popAddressLabel.numberOfLines = 2;
    //confirm
    
    UIButton *popConfirmBtn = [UIButton new];
    [_dimView addSubview:popConfirmBtn];
    [popConfirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(30*KScreenWidthScale750);
        make.right.mas_equalTo(-30*KScreenWidthScale750);
        make.bottom.mas_equalTo(-40*KScreenHeightScale1334);
        make.height.mas_equalTo(110*KScreenHeightScale1334);
    }];
    popConfirmBtn.layer.cornerRadius = 5.0;
    popConfirmBtn.layer.masksToBounds = YES;
    popConfirmBtn.titleLabel.font = KOverstrikingfont(36);
    [popConfirmBtn setTitle:Localized(@"确定") forState:(UIControlStateNormal)];
    [popConfirmBtn setTitleColor:kWhiteColor forState:UIControlStateNormal];
    [popConfirmBtn setBackgroundColor:kRedOrangeColor];
    //事件
    [backBtn addTarget:self action:@selector(backBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [popConfirmBtn addTarget:self action:@selector(popConfirmBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [FCPopupView showWithView:_dimView];
    
    
}
#pragma mark-验证pin
-(void)popConfirmBtnClick{
    [FCPopupView dissMiss];
 
    FCImportPinVC *vc = [FCImportPinVC new];
    vc.walletId = self.walletId;
    vc.addressStr = self.popAddressLabel.text.trimWhitespace;
    vc.moneyCountStr = self.popMoneyCountLable.text.trimWhitespace;
    vc.currentResultModel = self.currentResultModel;
    [self.navigationController pushViewController:vc animated:YES];
    
}
#pragma mark-二维码扫描
-(void)codeBtnClick{
    __weak __typeof(self)wself = self;
    FCSendScanCodeVC *vc = [FCSendScanCodeVC new];
    vc.isOtherVC = YES;
    vc.walletId = self.walletId;
    [vc setAddress:^(NSString*address){
        wself.addressField.text = address;
        
    }];
    [self.navigationController pushViewController:vc animated:YES];
    
}
//返回
-(void)backBtnClick{
    [FCPopupView dissMiss];
}
#pragma mark-设置UI
-(void)setupUI{
   //货币余额
    UILabel *balanceLabel = [UILabel new];
    self.balanceLabel = balanceLabel;
    [self.view addSubview:balanceLabel];
    [balanceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(30*KScreenWidthScale750);
        make.top.mas_equalTo(100*KScreenHeightScale1334);
    }];
//    balanceLabel.text = [NSString stringWithFormat:@"%@%@",Localized(@"比特币"),Localized(@"钱包余额")];
    balanceLabel.font = Kfont(32);
    balanceLabel.textColor = kGrayColor;
    
    //交易金额
    UILabel *moneyCountLable = [UILabel new];
    self.moneyCountLable = moneyCountLable;
    [self.view addSubview:moneyCountLable];
    [moneyCountLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(balanceLabel.mas_bottom).offset(30*KScreenHeightScale1334);
        make.left.mas_equalTo(30*KScreenWidthScale750);
    }];
    moneyCountLable.text = @"0.000000";
    moneyCountLable.font = Kfont(40);
    //usd
    UILabel *usdLable = [UILabel new];
    self.usdLable = usdLable;
    [self.view addSubview:usdLable];
    [usdLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(moneyCountLable).offset(-2);
        make.left.mas_equalTo(moneyCountLable.mas_right).offset(10*KScreenWidthScale750);
    }];
    usdLable.text = @"USD";
    usdLable.font = Kfont(32);
    usdLable.textColor = kOrderColor;
    //等值多少比特币
    UILabel *eqBtcLable = [UILabel new];
    self.eqBtcLable = eqBtcLable;
    [self.view addSubview:eqBtcLable];
    [eqBtcLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(moneyCountLable).offset(-4);
        make.left.mas_equalTo(usdLable.mas_right).offset(20*KScreenWidthScale750);
    }];
    eqBtcLable.text = @"(≈0.0000000 BTC)";
    eqBtcLable.font = Kfont(28);
    eqBtcLable.textColor = kGrayColor;
    
    //send
    UILabel *sendLable = [UILabel new];
    self.sendLable = sendLable;
    [self.view addSubview:sendLable];
    [sendLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(moneyCountLable.mas_bottom).offset(80*KScreenHeightScale1334);
        make.left.mas_equalTo(moneyCountLable);
    }];
    sendLable.text = Localized(@"发给");
    sendLable.font = Kfont(32);
    sendLable.textColor = kGrayColor;
    
    //地址
    UITextField *addressField = [UITextField new];
    self.addressField = addressField;
    [self.view addSubview:addressField];
    [addressField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(sendLable.mas_bottom).offset(40*KScreenHeightScale1334);
        make.left.mas_equalTo(30*KScreenWidthScale750);
        make.width.mas_equalTo(620*KScreenWidthScale750);
        
    }];
    addressField.delegate = self;
    addressField.placeholder = Localized(@"请输入地址");
    addressField.keyboardType = UIKeyboardTypeASCIICapable;
    if (self.isHomeQRcode) {
        addressField.text = self.addressStr;
    }
   
    //二维码
    UIButton *codeBtn = [UIButton new];
    [self.view addSubview:codeBtn];
    [codeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(addressField.mas_right).offset(30*KScreenWidthScale750);
        make.bottom.mas_equalTo(addressField);
    }];
    [codeBtn setBackgroundImage:[UIImage imageNamed:@"qrcode"] forState:UIControlStateNormal];
    //分割线
    UIView *viewLine =[UIView new];
    [self.view addSubview:viewLine];
    [viewLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(addressField);
        make.bottom.mas_equalTo(codeBtn);
        make.height.mas_equalTo(1);
    }];
    viewLine.backgroundColor =kLineColor;
   //amount
    UILabel *amountLable = [UILabel new];
    [self.view addSubview:amountLable];
    [amountLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(viewLine.mas_bottom).offset(80*KScreenHeightScale1334);
        make.left.mas_equalTo(moneyCountLable);
    }];
    amountLable.text = Localized(@"数量");
    amountLable.font = Kfont(32);
    amountLable.textColor = kGrayColor;
    //sendField
    UITextField *sendField = [UITextField new];
    self.sendField = sendField;
    [self.view addSubview:sendField];
    [sendField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(amountLable.mas_bottom).offset(30*KScreenHeightScale1334);
        make.left.mas_equalTo(30*KScreenWidthScale750);
        make.width.mas_equalTo(220*KScreenWidthScale750);
        
    }];
    sendField.placeholder = Localized(@"0");
    sendField.keyboardType = UIKeyboardTypeDecimalPad;
    sendField.delegate = self;
    [sendField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingDidEnd];
    
    //分割线2
    UIView *viewLine2 =[UIView new];
    [self.view addSubview:viewLine2];
    [viewLine2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(sendField);
        make.top.mas_equalTo(sendField.mas_bottom);
        make.height.mas_equalTo(1);
        make.width.mas_equalTo(280*KScreenWidthScale750);
    }];
    viewLine2.backgroundColor =kLineColor;
    //币种
    UILabel *currencyLable = [UILabel new];
    self.currencyLable = currencyLable;
    [self.view addSubview:currencyLable];
    [currencyLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(viewLine2.mas_bottom).offset(-2);
        make.right.mas_equalTo(viewLine2);
    }];
    currencyLable.text = @"BTC";
    currencyLable.font = Kfont(28);
    currencyLable.textColor = kOrderColor;
    //=
    UILabel *equalLabel = [UILabel new];
    self.equalLabel = equalLabel;
    [self.view addSubview:equalLabel];
    [equalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(viewLine2.mas_bottom).offset(-10*KScreenHeightScale1334);
        make.left.mas_equalTo(viewLine2.mas_right).offset(60*KScreenWidthScale750);
    }];
    equalLabel.text = @"=";
    equalLabel.font = Kfont(28);
    equalLabel.textColor = kDarkBlackColor;
    //receiveLabel
    UITextField *receiveField = [UITextField new];
    self.receiveField = receiveField;
    [self.view addSubview:receiveField];
    [receiveField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(amountLable.mas_bottom).offset(30*KScreenHeightScale1334);
        make.left.mas_equalTo(equalLabel.mas_right).offset(60*KScreenWidthScale750);
        make.width.mas_equalTo(220*KScreenWidthScale750);
        
    }];
    receiveField.placeholder = Localized(@"0");
    receiveField.userInteractionEnabled = NO;
   
    //分割线3
    UIView *viewLine3 =[UIView new];
    self.viewLine3 = viewLine3;
    [self.view addSubview:viewLine3];
    [viewLine3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(receiveField);
        make.top.mas_equalTo(receiveField.mas_bottom);
        make.height.mas_equalTo(1);
        make.width.mas_equalTo(280*KScreenWidthScale750);
    }];
    viewLine3.backgroundColor =kLineColor;
    //币种
    UILabel *currencyUSDLable = [UILabel new];
    self.currencyUSDLable = currencyUSDLable;
    [self.view addSubview:currencyUSDLable];
    [currencyUSDLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(viewLine3.mas_bottom).offset(-2);
        make.right.mas_equalTo(viewLine3);
    }];
    currencyUSDLable.text = @"USD";
    currencyUSDLable.font = Kfont(28);
    currencyUSDLable.textColor = kOrderColor;
    //Fee
    
    UILabel *feeLable = [UILabel new];
    [self.view addSubview:feeLable];
    [feeLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(viewLine2.mas_bottom).offset(80*KScreenHeightScale1334);
        make.left.mas_equalTo(30*KScreenWidthScale750);
    }];
    feeLable.text = Localized(@"手续费");
    feeLable.font = Kfont(32);
    feeLable.textColor = kOrderColor;
    
    //fennCountLabel
    UILabel *feeCountLable = [UILabel new];
    self.feeCountLable = feeCountLable;
    [self.view addSubview:feeCountLable];
    [feeCountLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(feeLable.mas_bottom).offset(30*KScreenHeightScale1334);
        make.left.mas_equalTo(30*KScreenWidthScale750);
    }];
    feeCountLable.text = @"0";
    feeCountLable.font = Kfont(36);
    feeCountLable.textColor = kDarkBlackColor;
    //usdLabel
    UILabel *feeUsdLabel = [UILabel new];
    self.feeUsdLabel = feeUsdLabel;
    [self.view addSubview:feeUsdLabel];
    [feeUsdLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(feeCountLable.mas_bottom).offset(-2);
        make.left.mas_equalTo(feeCountLable.mas_right).offset(10*KScreenWidthScale750);
    }];
    feeUsdLabel.text = @"USD";
    feeUsdLabel.font = Kfont(28);
    feeUsdLabel.textColor = kOrderColor;
    
    //sendBtn
    UIButton *sendBtn = [UIButton new];
    self.sendBtn = sendBtn;
    [self.view addSubview:sendBtn];
    [sendBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(30*KScreenWidthScale750);
        make.right.mas_equalTo(-30*KScreenWidthScale750);
        make.bottom.mas_equalTo(-300*KScreenHeightScale1334);
        make.height.mas_equalTo(112*KScreenHeightScale1334);
    }];
    sendBtn.layer.cornerRadius = 5.0;
    sendBtn.layer.masksToBounds = YES;
    sendBtn.titleLabel.font = KOverstrikingfont(36);
    [sendBtn setTitle:Localized(@"发送") forState:(UIControlStateNormal)];
    [sendBtn setTitleColor:kWhiteColor forState:UIControlStateNormal];
    [sendBtn setBackgroundColor:kLightblueColor];
    if (SCREEN_WIDTH == 320) {
        [sendBtn mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(-270*KScreenHeightScale1334);
        }];
    }
    
    
    
    //事件
    [sendBtn addTarget:self action:@selector(sendBtnClick) forControlEvents:UIControlEventTouchUpInside];
    //扫描
    
    [codeBtn addTarget:self action:@selector(codeBtnClick) forControlEvents:UIControlEventTouchUpInside];
    switch ([self.walletId integerValue]) {
        case 1001:
        {
           self.balanceLabel.text = Localized(@"BTC钱包余额");
        }
            break;
        case 1005:
        {
          self.balanceLabel.text = Localized(@"LTC钱包余额");
        }
            break;
        case 1006:
        {
           self.balanceLabel.text = Localized(@"BCH钱包余额");
        }
            break;
        case 1010:
        {
           self.balanceLabel.text = Localized(@"ZEC钱包余额");
        }
            break;
            
        default:
            break;
    }
    
    
    if ([self.walletId isEqualToString:@"1009"]) {
        //先隐藏
        self.balanceLabel.hidden = YES;
        self.eqBtcLable.hidden = YES;
        self.moneyCountLable.hidden = YES;
        self.usdLable.hidden = YES;
        self.receiveField.hidden = YES;
        self.equalLabel.hidden = YES;
        self.currencyUSDLable.hidden = YES;
        self.viewLine3.hidden = YES;
        self.currencyLable.text = @"CCH";
        self.feeUsdLabel.text = @"CCH";
        NSArray *arr = [FCLocalUserHelper getAllBalanceModel];
        [arr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            FCBalanceModel *model = obj;
            if ([model.walletId isEqualToString:@"1009"]) {
               self.feeCountLable.text = [NSString stringWithFormat:@"%.2f",[model.fee floatValue]];
            }
            
        }];
        
        [self.sendLable mas_updateConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(30*KScreenWidthScale750);
                make.top.mas_equalTo(100*KScreenHeightScale1334);
            }];
        
    }
}

#pragma mark-设置输入框的限制

-(void)textFieldDidChange:(UITextField *)textField{
    if (self.sendField == textField) {
        if ([textField.text containsString:@"."]) {
            NSString *str = textField.text;
            NSArray *array = [str componentsSeparatedByString:@"."]; //从字符A中分隔成2个元素的数组
            NSRange range = [str rangeOfString:@"."];
            //            NSString * result = [str substringFromIndex:range.location];
            NSString *s = [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
            
            if (s.length - range.location >8 ) {
                NSRange range2 = [str rangeOfString:@"."];
                NSString * result = [str substringFromIndex:range2.location];
                NSLog(@"%@",[result substringWithRange:NSMakeRange(0, 9)]);
                
                textField.text = [NSString stringWithFormat:@"%@%@",array[0],[result substringWithRange:NSMakeRange(0, 9)]];
                
            }
        }
        //高精度计算法
        NSDecimalNumber *productPrice = [NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:@"%f",[self.sendField.text.trimWhitespace floatValue]]];
        
        NSDecimalNumber *productNumber = [NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:@"%.8f",[self.priceStr floatValue]]];
        NSDecimalNumber *totalAmount = [productPrice decimalNumberByMultiplyingBy:productNumber];
        self.receiveField.text = [NSString stringWithFormat:@"%.2f",[totalAmount floatValue]];
        NSLog(@"%@==%@====%@",productPrice,productNumber,totalAmount);
        
        if (self.sendField.text.trimWhitespace.length > 0 ) {
            
            [self.sendBtn setBackgroundColor:kRedOrangeColor];
            
        }else{
            [self.sendBtn setBackgroundColor:kLightblueColor];
        }
        FCCurrentResultModel *currentResultModel = self.currentResultModel;
        
        if ([currentResultModel.walletId isEqualToString:self.walletId]) {
            
            float result = [currentResultModel.price floatValue]*[self.sendField.text.trimWhitespace floatValue];
            self.receiveField.text = [NSString stringWithFormat:@"%.2f",result];
            
        }
        
    }
}

#pragma mark - 键盘弹出时界面上移及还原
-(void)keyBoardWillShow:(NSNotification *) notification{
    
    //获取键盘的高度
    NSDictionary *userInfo = [notification userInfo];
    NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGRect keyboardRect = [aValue CGRectValue];
    int keyBoardHeight = keyboardRect.size.height;
    
    //使视图上移
    CGRect viewFrame = self.view.frame;
    
    viewFrame.origin.y = -keyBoardHeight/2;//上移1/2的键盘高度
    self.view.frame = viewFrame;
    
}

- (void)keyBoardWillHide:(NSNotification *) notification {
    //当键盘消失时执行方法使视图下滑回原位
    NSTimeInterval time = [[notification.userInfo objectForKey:@"UIKeyboardAnimationDurationUserInfoKey"] floatValue];
    [UIView animateWithDuration:time animations:^{
        CGRect frame = self.view.frame;
        frame.origin.y = 0;
        self.view.frame = frame;
        [self.view layoutIfNeeded];
    }];
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    //移除第一响应
    [self.sendField resignFirstResponder];
    [self.addressField resignFirstResponder];
    
}


@end
